﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Evaluant.Uss.Common;
using Microsoft.Isam.Esent.Interop;

namespace EsentProvider
{
    public class Factory : PersistenceEngineFactoryImplementation
    {
        string m_DatabaseFileName = null;
        Instance m_Instance = null;

        public override void InitializeConfiguration()
        {
            m_DatabaseFileName = "euss.edb";

            InitDB();
        }

        void InitDB()
        {
            using (var instance = new Instance("createdatabase"))
            {
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, m_DatabaseFileName, null, out dbid, CreateDatabaseGrbit.OverwriteExisting);
                }
            }

            m_Instance = new Instance(m_DatabaseFileName);            
        }

        public override void RegisterMetaData(Evaluant.Uss.MetaData.IMetaData[] metadata)
        {
            base.RegisterMetaData(metadata);

            MaintainDatabaseStructure();
        }

        private void MaintainDatabaseStructure()
        {
            throw new NotImplementedException();
        }

        public override Evaluant.Uss.IPersistenceEngine CreatePersistenceEngine()
        {
            throw new NotImplementedException();
        }
    }
}
